{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Clojupyter + oz example\n",
    "\n",
    "This notebook demonstrates basic usage of oz from a Jupyter notebook using the Clojuypyter kernel.\n",
    "\n",
    "Note that the visualizations below may not render if you're looking at this on GitHub, but will render if you load the notebook into a running Jupyter instance."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "(require '[clojupyter.misc.helper :as helper])\n",
    "(helper/add-dependencies '[metasoarous/oz \"1.5.0\"])\n",
    "(require '[oz.notebook.clojupyter :as oz])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div>\n",
       "  <div id='uuid-96a99d22-6fc7-4f10-9087-727cf3b35357'></div>\n",
       "  <script>\n",
       "  requirejs.config({\n",
       "    baseUrl: 'https://cdn.jsdelivr.net/npm/',\n",
       "    paths: {\n",
       "      'vega-embed':  'vega-embed@3?noext',\n",
       "      'vega-lib': 'vega-lib?noext',\n",
       "      'vega-lite': 'vega-lite@2?noext',\n",
       "      'vega': 'vega@3?noext'\n",
       "    }\n",
       "  });\n",
       "  require(['vega-embed'], function(vegaEmbed) {\n",
       "    let spec = {\"data\":{\"values\":[{\"time\":0,\"item\":\"munchkin\",\"quantity\":2.0},{\"time\":1,\"item\":\"munchkin\",\"quantity\":9.278031643091577},{\"time\":2,\"item\":\"munchkin\",\"quantity\":14.18958683997628},{\"time\":3,\"item\":\"munchkin\",\"quantity\":19.71068609258575},{\"time\":4,\"item\":\"munchkin\",\"quantity\":21.000000000000004},{\"time\":5,\"item\":\"munchkin\",\"quantity\":26.127049995800743},{\"time\":6,\"item\":\"munchkin\",\"quantity\":29.13058987556147},{\"time\":7,\"item\":\"munchkin\",\"quantity\":25.03516289842348},{\"time\":8,\"item\":\"munchkin\",\"quantity\":29.85761802547598},{\"time\":9,\"item\":\"munchkin\",\"quantity\":33.610188015018984},{\"time\":10,\"item\":\"munchkin\",\"quantity\":38.30212829607493},{\"time\":11,\"item\":\"munchkin\",\"quantity\":35.940667420160906},{\"time\":12,\"item\":\"munchkin\",\"quantity\":41.53159496449108},{\"time\":13,\"item\":\"munchkin\",\"quantity\":45.07964401264505},{\"time\":14,\"item\":\"munchkin\",\"quantity\":46.58875032686557},{\"time\":15,\"item\":\"munchkin\",\"quantity\":46.06223395648531},{\"time\":16,\"item\":\"munchkin\",\"quantity\":54.50293012833275},{\"time\":17,\"item\":\"munchkin\",\"quantity\":53.91328587177879},{\"time\":18,\"item\":\"munchkin\",\"quantity\":57.29543283815009},{\"time\":19,\"item\":\"munchkin\",\"quantity\":56.65124317675735},{\"time\":0,\"item\":\"witch\",\"quantity\":1.0},{\"time\":1,\"item\":\"witch\",\"quantity\":7.623898318388478},{\"time\":2,\"item\":\"witch\",\"quantity\":6.309573444801933},{\"time\":3,\"item\":\"witch\",\"quantity\":12.727161387290321},{\"time\":4,\"item\":\"witch\",\"quantity\":13.98560543306118},{\"time\":5,\"item\":\"witch\",\"quantity\":13.132639022018838},{\"time\":6,\"item\":\"witch\",\"quantity\":18.194870523363548},{\"time\":7,\"item\":\"witch\",\"quantity\":19.189151347155786},{\"time\":8,\"item\":\"witch\",\"quantity\":22.127049995800743},{\"time\":9,\"item\":\"witch\",\"quantity\":24.016965485301043},{\"time\":10,\"item\":\"witch\",\"quantity\":23.86525259636632},{\"time\":11,\"item\":\"witch\",\"quantity\":28.676874454922782},{\"time\":12,\"item\":\"witch\",\"quantity\":29.45580618665162},{\"time\":13,\"item\":\"witch\",\"quantity\":32.20529752834578},{\"time\":14,\"item\":\"witch\",\"quantity\":32.9280507756976},{\"time\":15,\"item\":\"witch\",\"quantity\":31.626345475706252},{\"time\":16,\"item\":\"witch\",\"quantity\":37.30212829607493},{\"time\":17,\"item\":\"witch\",\"quantity\":34.95707936800063},{\"time\":18,\"item\":\"witch\",\"quantity\":39.59266228400805},{\"time\":19,\"item\":\"witch\",\"quantity\":42.210162462449645},{\"time\":0,\"item\":\"dog\",\"quantity\":2.0},{\"time\":1,\"item\":\"dog\",\"quantity\":3.4082246852806923},{\"time\":2,\"item\":\"dog\",\"quantity\":6.192962712629476},{\"time\":3,\"item\":\"dog\",\"quantity\":6.799546134795289},{\"time\":4,\"item\":\"dog\",\"quantity\":8.30037210271847},{\"time\":5,\"item\":\"dog\",\"quantity\":10.727161387290321},{\"time\":6,\"item\":\"dog\",\"quantity\":10.097596309015797},{\"time\":7,\"item\":\"dog\",\"quantity\":11.42287530066645},{\"time\":8,\"item\":\"dog\",\"quantity\":14.71068609258575},{\"time\":9,\"item\":\"dog\",\"quantity\":13.966610165238238},{\"time\":10,\"item\":\"dog\",\"quantity\":17.194870523363548},{\"time\":11,\"item\":\"dog\",\"quantity\":17.398765361701578},{\"time\":12,\"item\":\"dog\",\"quantity\":17.580936309501134},{\"time\":13,\"item\":\"dog\",\"quantity\":19.74354294621998},{\"time\":14,\"item\":\"dog\",\"quantity\":19.888381054913122},{\"time\":15,\"item\":\"dog\",\"quantity\":21.016965485301043},{\"time\":16,\"item\":\"dog\",\"quantity\":22.13058987556147},{\"time\":17,\"item\":\"dog\",\"quantity\":24.230370739754015},{\"time\":18,\"item\":\"dog\",\"quantity\":25.317280693371046},{\"time\":19,\"item\":\"dog\",\"quantity\":25.392173948075055},{\"time\":0,\"item\":\"lion\",\"quantity\":3.0},{\"time\":1,\"item\":\"lion\",\"quantity\":3.0314331330207964},{\"time\":2,\"item\":\"lion\",\"quantity\":6.278031643091578},{\"time\":3,\"item\":\"lion\",\"quantity\":9.30037210271847},{\"time\":4,\"item\":\"lion\",\"quantity\":9.18958683997628},{\"time\":5,\"item\":\"lion\",\"quantity\":13.98560543306118},{\"time\":6,\"item\":\"lion\",\"quantity\":15.71068609258575},{\"time\":7,\"item\":\"lion\",\"quantity\":17.378925219250924},{\"time\":8,\"item\":\"lion\",\"quantity\":16.000000000000004},{\"time\":9,\"item\":\"lion\",\"quantity\":19.580936309501134},{\"time\":10,\"item\":\"lion\",\"quantity\":19.127049995800743},{\"time\":11,\"item\":\"lion\",\"quantity\":22.642492771517183},{\"time\":12,\"item\":\"lion\",\"quantity\":23.13058987556147},{\"time\":13,\"item\":\"lion\",\"quantity\":25.59405975059458},{\"time\":14,\"item\":\"lion\",\"quantity\":28.03516289842348},{\"time\":15,\"item\":\"lion\",\"quantity\":28.45580618665162},{\"time\":16,\"item\":\"lion\",\"quantity\":30.85761802547598},{\"time\":17,\"item\":\"lion\",\"quantity\":32.24200386420304},{\"time\":18,\"item\":\"lion\",\"quantity\":30.610188015018984},{\"time\":19,\"item\":\"lion\",\"quantity\":32.96324574534057},{\"time\":0,\"item\":\"tiger\",\"quantity\":1.0},{\"time\":1,\"item\":\"tiger\",\"quantity\":4.623898318388478},{\"time\":2,\"item\":\"tiger\",\"quantity\":8.309573444801934},{\"time\":3,\"item\":\"tiger\",\"quantity\":12.727161387290321},{\"time\":4,\"item\":\"tiger\",\"quantity\":13.98560543306118},{\"time\":5,\"item\":\"tiger\",\"quantity\":14.132639022018838},{\"time\":6,\"item\":\"tiger\",\"quantity\":19.194870523363548},{\"time\":7,\"item\":\"tiger\",\"quantity\":20.189151347155786},{\"time\":8,\"item\":\"tiger\",\"quantity\":19.127049995800743},{\"time\":9,\"item\":\"tiger\",\"quantity\":22.016965485301043},{\"time\":10,\"item\":\"tiger\",\"quantity\":23.86525259636632},{\"time\":11,\"item\":\"tiger\",\"quantity\":28.676874454922782},{\"time\":12,\"item\":\"tiger\",\"quantity\":30.45580618665162},{\"time\":13,\"item\":\"tiger\",\"quantity\":29.205297528345778},{\"time\":14,\"item\":\"tiger\",\"quantity\":31.928050775697603},{\"time\":15,\"item\":\"tiger\",\"quantity\":34.62634547570625},{\"time\":16,\"item\":\"tiger\",\"quantity\":36.30212829607493},{\"time\":17,\"item\":\"tiger\",\"quantity\":35.95707936800063},{\"time\":18,\"item\":\"tiger\",\"quantity\":40.59266228400805},{\"time\":19,\"item\":\"tiger\",\"quantity\":42.210162462449645},{\"time\":0,\"item\":\"bear\",\"quantity\":0.0},{\"time\":1,\"item\":\"bear\",\"quantity\":6.031433133020796},{\"time\":2,\"item\":\"bear\",\"quantity\":6.278031643091578},{\"time\":3,\"item\":\"bear\",\"quantity\":10.30037210271847},{\"time\":4,\"item\":\"bear\",\"quantity\":11.18958683997628},{\"time\":5,\"item\":\"bear\",\"quantity\":11.98560543306118},{\"time\":6,\"item\":\"bear\",\"quantity\":14.71068609258575},{\"time\":7,\"item\":\"bear\",\"quantity\":17.378925219250924},{\"time\":8,\"item\":\"bear\",\"quantity\":16.000000000000004},{\"time\":9,\"item\":\"bear\",\"quantity\":18.580936309501134},{\"time\":10,\"item\":\"bear\",\"quantity\":22.127049995800743},{\"time\":11,\"item\":\"bear\",\"quantity\":22.642492771517183},{\"time\":12,\"item\":\"bear\",\"quantity\":22.13058987556147},{\"time\":13,\"item\":\"bear\",\"quantity\":25.59405975059458},{\"time\":14,\"item\":\"bear\",\"quantity\":25.03516289842348},{\"time\":15,\"item\":\"bear\",\"quantity\":27.45580618665162},{\"time\":16,\"item\":\"bear\",\"quantity\":27.85761802547598},{\"time\":17,\"item\":\"bear\",\"quantity\":32.24200386420304},{\"time\":18,\"item\":\"bear\",\"quantity\":31.610188015018984},{\"time\":19,\"item\":\"bear\",\"quantity\":31.96324574534057}]},\"mark\":\"bar\",\"encoding\":{\"x\":{\"field\":\"time\"},\"y\":{\"aggregate\":\"sum\",\"field\":\"quantity\",\"type\":\"quantitative\"},\"color\":{\"field\":\"item\"}}};\n",
       "    vegaEmbed('#uuid-96a99d22-6fc7-4f10-9087-727cf3b35357', spec, {defaultStyle:true}).catch(console.warn);\n",
       "    }, function(err) {\n",
       "    console.log('Failed to load');\n",
       "  });\n",
       "  </script>\n",
       "</div>\n",
       "  "
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(defn play-data [& names]\n",
    "  (for [n names\n",
    "        i (range 20)]\n",
    "    {:time i :item n :quantity (+ (Math/pow (* i (count n)) 0.8) (rand-int (count n)))}))\n",
    "    \n",
    "(def stacked-bar\n",
    "  {:data {:values (play-data \"munchkin\" \"witch\" \"dog\" \"lion\" \"tiger\" \"bear\")}\n",
    "   :mark \"bar\"\n",
    "   :encoding {:x {:field \"time\"}\n",
    "              :y {:aggregate \"sum\"\n",
    "                  :field \"quantity\"\n",
    "                  :type \"quantitative\"}\n",
    "              :color {:field \"item\"}}})\n",
    "(oz/view! stacked-bar)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div>\n",
       "  <div id='uuid-20045024-43c9-401b-8a7e-65a3f180f25f'></div>\n",
       "  <script>\n",
       "  requirejs.config({\n",
       "    baseUrl: 'https://cdn.jsdelivr.net/npm/',\n",
       "    paths: {\n",
       "      'vega-embed':  'vega-embed@3?noext',\n",
       "      'vega-lib': 'vega-lib?noext',\n",
       "      'vega-lite': 'vega-lite@2?noext',\n",
       "      'vega': 'vega@3?noext'\n",
       "    }\n",
       "  });\n",
       "  require(['vega-embed'], function(vegaEmbed) {\n",
       "    let spec = {\"data\":{\"url\":\"https:\\/\\/gist.githubusercontent.com\\/metasoarous\\/4e6f781d353322a44b9cd3e4597c532c\\/raw\\/cd633d9bb8e0bed4a5b8e66a32b9569ca2147989\\/cars.json\"},\"mark\":\"point\",\"encoding\":{\"x\":{\"field\":\"Horsepower\",\"type\":\"quantitative\"},\"y\":{\"field\":\"Miles_per_Gallon\",\"type\":\"quantitative\"},\"color\":{\"field\":\"Origin\",\"type\":\"nominal\"}}};\n",
       "    vegaEmbed('#uuid-20045024-43c9-401b-8a7e-65a3f180f25f', spec, {defaultStyle:true}).catch(console.warn);\n",
       "    }, function(err) {\n",
       "    console.log('Failed to load');\n",
       "  });\n",
       "  </script>\n",
       "</div>\n",
       "  "
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "              \n",
    ";; Create spec, then visualize\n",
    "(def spec\n",
    "  {:data {:url \"https://gist.githubusercontent.com/metasoarous/4e6f781d353322a44b9cd3e4597c532c/raw/cd633d9bb8e0bed4a5b8e66a32b9569ca2147989/cars.json\"}\n",
    "   :mark \"point\"\n",
    "   :encoding {\n",
    "     :x {:field \"Horsepower\", :type \"quantitative\"}\n",
    "     :y {:field \"Miles_per_Gallon\", :type \"quantitative\"}\n",
    "     :color {:field \"Origin\", :type \"nominal\"}}})\n",
    "(oz/view! spec)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><h1>A little hiccup example</h1><p>Try drinking a glass of water with your head upside down</p><div style=\"{:display &quot;flex&quot;, :flex-direction &quot;row&quot;}\">\n",
       "<div>\n",
       "  <div id='uuid-fd9f04fc-9e6a-406c-9918-ca9a31c85809'></div>\n",
       "  <script>\n",
       "  requirejs.config({\n",
       "    baseUrl: 'https://cdn.jsdelivr.net/npm/',\n",
       "    paths: {\n",
       "      'vega-embed':  'vega-embed@3?noext',\n",
       "      'vega-lib': 'vega-lib?noext',\n",
       "      'vega-lite': 'vega-lite@2?noext',\n",
       "      'vega': 'vega@3?noext'\n",
       "    }\n",
       "  });\n",
       "  require(['vega-embed'], function(vegaEmbed) {\n",
       "    let spec = {\"data\":{\"url\":\"https:\\/\\/gist.githubusercontent.com\\/metasoarous\\/4e6f781d353322a44b9cd3e4597c532c\\/raw\\/cd633d9bb8e0bed4a5b8e66a32b9569ca2147989\\/cars.json\"},\"mark\":\"point\",\"encoding\":{\"x\":{\"field\":\"Horsepower\",\"type\":\"quantitative\"},\"y\":{\"field\":\"Miles_per_Gallon\",\"type\":\"quantitative\"},\"color\":{\"field\":\"Origin\",\"type\":\"nominal\"}}};\n",
       "    vegaEmbed('#uuid-fd9f04fc-9e6a-406c-9918-ca9a31c85809', spec, {defaultStyle:true}).catch(console.warn);\n",
       "    }, function(err) {\n",
       "    console.log('Failed to load');\n",
       "  });\n",
       "  </script>\n",
       "</div>\n",
       "  \n",
       "<div>\n",
       "  <div id='uuid-a75f5521-a5a8-41b9-8c02-1de47e9276c0'></div>\n",
       "  <script>\n",
       "  requirejs.config({\n",
       "    baseUrl: 'https://cdn.jsdelivr.net/npm/',\n",
       "    paths: {\n",
       "      'vega-embed':  'vega-embed@3?noext',\n",
       "      'vega-lib': 'vega-lib?noext',\n",
       "      'vega-lite': 'vega-lite@2?noext',\n",
       "      'vega': 'vega@3?noext'\n",
       "    }\n",
       "  });\n",
       "  require(['vega-embed'], function(vegaEmbed) {\n",
       "    let spec = {\"data\":{\"values\":[{\"time\":0,\"item\":\"munchkin\",\"quantity\":2.0},{\"time\":1,\"item\":\"munchkin\",\"quantity\":9.278031643091577},{\"time\":2,\"item\":\"munchkin\",\"quantity\":14.18958683997628},{\"time\":3,\"item\":\"munchkin\",\"quantity\":19.71068609258575},{\"time\":4,\"item\":\"munchkin\",\"quantity\":21.000000000000004},{\"time\":5,\"item\":\"munchkin\",\"quantity\":26.127049995800743},{\"time\":6,\"item\":\"munchkin\",\"quantity\":29.13058987556147},{\"time\":7,\"item\":\"munchkin\",\"quantity\":25.03516289842348},{\"time\":8,\"item\":\"munchkin\",\"quantity\":29.85761802547598},{\"time\":9,\"item\":\"munchkin\",\"quantity\":33.610188015018984},{\"time\":10,\"item\":\"munchkin\",\"quantity\":38.30212829607493},{\"time\":11,\"item\":\"munchkin\",\"quantity\":35.940667420160906},{\"time\":12,\"item\":\"munchkin\",\"quantity\":41.53159496449108},{\"time\":13,\"item\":\"munchkin\",\"quantity\":45.07964401264505},{\"time\":14,\"item\":\"munchkin\",\"quantity\":46.58875032686557},{\"time\":15,\"item\":\"munchkin\",\"quantity\":46.06223395648531},{\"time\":16,\"item\":\"munchkin\",\"quantity\":54.50293012833275},{\"time\":17,\"item\":\"munchkin\",\"quantity\":53.91328587177879},{\"time\":18,\"item\":\"munchkin\",\"quantity\":57.29543283815009},{\"time\":19,\"item\":\"munchkin\",\"quantity\":56.65124317675735},{\"time\":0,\"item\":\"witch\",\"quantity\":1.0},{\"time\":1,\"item\":\"witch\",\"quantity\":7.623898318388478},{\"time\":2,\"item\":\"witch\",\"quantity\":6.309573444801933},{\"time\":3,\"item\":\"witch\",\"quantity\":12.727161387290321},{\"time\":4,\"item\":\"witch\",\"quantity\":13.98560543306118},{\"time\":5,\"item\":\"witch\",\"quantity\":13.132639022018838},{\"time\":6,\"item\":\"witch\",\"quantity\":18.194870523363548},{\"time\":7,\"item\":\"witch\",\"quantity\":19.189151347155786},{\"time\":8,\"item\":\"witch\",\"quantity\":22.127049995800743},{\"time\":9,\"item\":\"witch\",\"quantity\":24.016965485301043},{\"time\":10,\"item\":\"witch\",\"quantity\":23.86525259636632},{\"time\":11,\"item\":\"witch\",\"quantity\":28.676874454922782},{\"time\":12,\"item\":\"witch\",\"quantity\":29.45580618665162},{\"time\":13,\"item\":\"witch\",\"quantity\":32.20529752834578},{\"time\":14,\"item\":\"witch\",\"quantity\":32.9280507756976},{\"time\":15,\"item\":\"witch\",\"quantity\":31.626345475706252},{\"time\":16,\"item\":\"witch\",\"quantity\":37.30212829607493},{\"time\":17,\"item\":\"witch\",\"quantity\":34.95707936800063},{\"time\":18,\"item\":\"witch\",\"quantity\":39.59266228400805},{\"time\":19,\"item\":\"witch\",\"quantity\":42.210162462449645},{\"time\":0,\"item\":\"dog\",\"quantity\":2.0},{\"time\":1,\"item\":\"dog\",\"quantity\":3.4082246852806923},{\"time\":2,\"item\":\"dog\",\"quantity\":6.192962712629476},{\"time\":3,\"item\":\"dog\",\"quantity\":6.799546134795289},{\"time\":4,\"item\":\"dog\",\"quantity\":8.30037210271847},{\"time\":5,\"item\":\"dog\",\"quantity\":10.727161387290321},{\"time\":6,\"item\":\"dog\",\"quantity\":10.097596309015797},{\"time\":7,\"item\":\"dog\",\"quantity\":11.42287530066645},{\"time\":8,\"item\":\"dog\",\"quantity\":14.71068609258575},{\"time\":9,\"item\":\"dog\",\"quantity\":13.966610165238238},{\"time\":10,\"item\":\"dog\",\"quantity\":17.194870523363548},{\"time\":11,\"item\":\"dog\",\"quantity\":17.398765361701578},{\"time\":12,\"item\":\"dog\",\"quantity\":17.580936309501134},{\"time\":13,\"item\":\"dog\",\"quantity\":19.74354294621998},{\"time\":14,\"item\":\"dog\",\"quantity\":19.888381054913122},{\"time\":15,\"item\":\"dog\",\"quantity\":21.016965485301043},{\"time\":16,\"item\":\"dog\",\"quantity\":22.13058987556147},{\"time\":17,\"item\":\"dog\",\"quantity\":24.230370739754015},{\"time\":18,\"item\":\"dog\",\"quantity\":25.317280693371046},{\"time\":19,\"item\":\"dog\",\"quantity\":25.392173948075055},{\"time\":0,\"item\":\"lion\",\"quantity\":3.0},{\"time\":1,\"item\":\"lion\",\"quantity\":3.0314331330207964},{\"time\":2,\"item\":\"lion\",\"quantity\":6.278031643091578},{\"time\":3,\"item\":\"lion\",\"quantity\":9.30037210271847},{\"time\":4,\"item\":\"lion\",\"quantity\":9.18958683997628},{\"time\":5,\"item\":\"lion\",\"quantity\":13.98560543306118},{\"time\":6,\"item\":\"lion\",\"quantity\":15.71068609258575},{\"time\":7,\"item\":\"lion\",\"quantity\":17.378925219250924},{\"time\":8,\"item\":\"lion\",\"quantity\":16.000000000000004},{\"time\":9,\"item\":\"lion\",\"quantity\":19.580936309501134},{\"time\":10,\"item\":\"lion\",\"quantity\":19.127049995800743},{\"time\":11,\"item\":\"lion\",\"quantity\":22.642492771517183},{\"time\":12,\"item\":\"lion\",\"quantity\":23.13058987556147},{\"time\":13,\"item\":\"lion\",\"quantity\":25.59405975059458},{\"time\":14,\"item\":\"lion\",\"quantity\":28.03516289842348},{\"time\":15,\"item\":\"lion\",\"quantity\":28.45580618665162},{\"time\":16,\"item\":\"lion\",\"quantity\":30.85761802547598},{\"time\":17,\"item\":\"lion\",\"quantity\":32.24200386420304},{\"time\":18,\"item\":\"lion\",\"quantity\":30.610188015018984},{\"time\":19,\"item\":\"lion\",\"quantity\":32.96324574534057},{\"time\":0,\"item\":\"tiger\",\"quantity\":1.0},{\"time\":1,\"item\":\"tiger\",\"quantity\":4.623898318388478},{\"time\":2,\"item\":\"tiger\",\"quantity\":8.309573444801934},{\"time\":3,\"item\":\"tiger\",\"quantity\":12.727161387290321},{\"time\":4,\"item\":\"tiger\",\"quantity\":13.98560543306118},{\"time\":5,\"item\":\"tiger\",\"quantity\":14.132639022018838},{\"time\":6,\"item\":\"tiger\",\"quantity\":19.194870523363548},{\"time\":7,\"item\":\"tiger\",\"quantity\":20.189151347155786},{\"time\":8,\"item\":\"tiger\",\"quantity\":19.127049995800743},{\"time\":9,\"item\":\"tiger\",\"quantity\":22.016965485301043},{\"time\":10,\"item\":\"tiger\",\"quantity\":23.86525259636632},{\"time\":11,\"item\":\"tiger\",\"quantity\":28.676874454922782},{\"time\":12,\"item\":\"tiger\",\"quantity\":30.45580618665162},{\"time\":13,\"item\":\"tiger\",\"quantity\":29.205297528345778},{\"time\":14,\"item\":\"tiger\",\"quantity\":31.928050775697603},{\"time\":15,\"item\":\"tiger\",\"quantity\":34.62634547570625},{\"time\":16,\"item\":\"tiger\",\"quantity\":36.30212829607493},{\"time\":17,\"item\":\"tiger\",\"quantity\":35.95707936800063},{\"time\":18,\"item\":\"tiger\",\"quantity\":40.59266228400805},{\"time\":19,\"item\":\"tiger\",\"quantity\":42.210162462449645},{\"time\":0,\"item\":\"bear\",\"quantity\":0.0},{\"time\":1,\"item\":\"bear\",\"quantity\":6.031433133020796},{\"time\":2,\"item\":\"bear\",\"quantity\":6.278031643091578},{\"time\":3,\"item\":\"bear\",\"quantity\":10.30037210271847},{\"time\":4,\"item\":\"bear\",\"quantity\":11.18958683997628},{\"time\":5,\"item\":\"bear\",\"quantity\":11.98560543306118},{\"time\":6,\"item\":\"bear\",\"quantity\":14.71068609258575},{\"time\":7,\"item\":\"bear\",\"quantity\":17.378925219250924},{\"time\":8,\"item\":\"bear\",\"quantity\":16.000000000000004},{\"time\":9,\"item\":\"bear\",\"quantity\":18.580936309501134},{\"time\":10,\"item\":\"bear\",\"quantity\":22.127049995800743},{\"time\":11,\"item\":\"bear\",\"quantity\":22.642492771517183},{\"time\":12,\"item\":\"bear\",\"quantity\":22.13058987556147},{\"time\":13,\"item\":\"bear\",\"quantity\":25.59405975059458},{\"time\":14,\"item\":\"bear\",\"quantity\":25.03516289842348},{\"time\":15,\"item\":\"bear\",\"quantity\":27.45580618665162},{\"time\":16,\"item\":\"bear\",\"quantity\":27.85761802547598},{\"time\":17,\"item\":\"bear\",\"quantity\":32.24200386420304},{\"time\":18,\"item\":\"bear\",\"quantity\":31.610188015018984},{\"time\":19,\"item\":\"bear\",\"quantity\":31.96324574534057}]},\"mark\":\"bar\",\"encoding\":{\"x\":{\"field\":\"time\"},\"y\":{\"aggregate\":\"sum\",\"field\":\"quantity\",\"type\":\"quantitative\"},\"color\":{\"field\":\"item\"}}};\n",
       "    vegaEmbed('#uuid-a75f5521-a5a8-41b9-8c02-1de47e9276c0', spec, {defaultStyle:true}).catch(console.warn);\n",
       "    }, function(err) {\n",
       "    console.log('Failed to load');\n",
       "  });\n",
       "  </script>\n",
       "</div>\n",
       "  </div></div>"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(oz/view!\n",
    "  [:div\n",
    "   [:h1 \"A little hiccup example\"]\n",
    "   [:p \"Try drinking a glass of water with your head upside down\"]\n",
    "   [:div {:style {:display \"flex\" :flex-direction \"row\"}}\n",
    "    [:vega-lite spec]\n",
    "    [:vega-lite stacked-bar]]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div>\n",
       "  <div id='uuid-7eeb3992-0fa1-4488-83f4-92881a3c4fb4'></div>\n",
       "  <script>\n",
       "  requirejs.config({\n",
       "    baseUrl: 'https://cdn.jsdelivr.net/npm/',\n",
       "    paths: {\n",
       "      'vega-embed':  'vega-embed@3?noext',\n",
       "      'vega-lib': 'vega-lib?noext',\n",
       "      'vega-lite': 'vega-lite@2?noext',\n",
       "      'vega': 'vega@3?noext'\n",
       "    }\n",
       "  });\n",
       "  require(['vega-embed'], function(vegaEmbed) {\n",
       "    let spec = {\"style\":\"cell\",\"width\":200,\"height\":200,\"data\":[{\"name\":\"source_0\",\"url\":\"https:\\/\\/gist.githubusercontent.com\\/metasoarous\\/4e6f781d353322a44b9cd3e4597c532c\\/raw\\/cd633d9bb8e0bed4a5b8e66a32b9569ca2147989\\/cars.json\",\"format\":{\"type\":\"json\"}}],\"marks\":[{\"name\":\"marks\",\"type\":\"symbol\",\"style\":[\"point\"],\"from\":{\"data\":\"source_0\"},\"encode\":{\"update\":{\"stroke\":{\"scale\":\"color\",\"field\":\"Origin\"},\"x\":{\"scale\":\"x\",\"field\":\"Horsepower\"},\"y\":{\"scale\":\"y\",\"field\":\"Miles_per_Gallon\"}}}}],\"scales\":[{\"name\":\"x\",\"type\":\"linear\",\"domain\":{\"data\":\"source_0\",\"field\":\"Horsepower\"},\"range\":[0,{\"signal\":\"width\"}]},{\"name\":\"y\",\"type\":\"linear\",\"domain\":{\"data\":\"source_0\",\"field\":\"Miles_per_Gallon\"},\"range\":[{\"signal\":\"height\"},0]},{\"name\":\"color\",\"type\":\"ordinal\",\"domain\":{\"data\":\"source_0\",\"field\":\"Origin\"},\"range\":\"category\"}]};\n",
       "    vegaEmbed('#uuid-7eeb3992-0fa1-4488-83f4-92881a3c4fb4', spec, {defaultStyle:true}).catch(console.warn);\n",
       "    }, function(err) {\n",
       "    console.log('Failed to load');\n",
       "  });\n",
       "  </script>\n",
       "</div>\n",
       "  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(def vg-spec\n",
    "  {:style \"cell\",\n",
    "   :width 200,\n",
    "   :height 200,\n",
    "   :data\n",
    "   [{:name \"source_0\",\n",
    "     :url \"https://gist.githubusercontent.com/metasoarous/4e6f781d353322a44b9cd3e4597c532c/raw/cd633d9bb8e0bed4a5b8e66a32b9569ca2147989/cars.json\",\n",
    "     :format {:type \"json\"}}],\n",
    "   :marks\n",
    "   [{:name \"marks\",\n",
    "     :type \"symbol\",\n",
    "     :style [\"point\"],\n",
    "     :from {:data \"source_0\"},\n",
    "     :encode\n",
    "     {:update\n",
    "      {:stroke {:scale \"color\", :field \"Origin\"},\n",
    "       :x {:scale \"x\", :field \"Horsepower\"},\n",
    "       :y {:scale \"y\", :field \"Miles_per_Gallon\"}}}}],\n",
    "   :scales\n",
    "   [{:name \"x\",\n",
    "     :type \"linear\",\n",
    "     :domain {:data \"source_0\", :field \"Horsepower\"},\n",
    "     :range [0 {:signal \"width\"}]}\n",
    "    {:name \"y\",\n",
    "     :type \"linear\",\n",
    "     :domain {:data \"source_0\", :field \"Miles_per_Gallon\"},\n",
    "     :range [{:signal \"height\"} 0]}\n",
    "    {:name \"color\",\n",
    "     :type \"ordinal\",\n",
    "     :domain {:data \"source_0\", :field \"Origin\"},\n",
    "     :range \"category\"}]})\n",
    "(oz/view! vg-spec)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#'user/shit"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(defn shit [x] x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Clojure",
   "language": "clojure",
   "name": "clojure"
  },
  "language_info": {
   "file_extension": ".clj",
   "mimetype": "text/x-clojure",
   "name": "clojure",
   "version": "1.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
